package com.ssm.studen.service.impl;

import com.ssm.studen.dao.ClassRoomDao;
import com.ssm.studen.model.ClassRoom;
import com.ssm.studen.service.ClassRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 班级表：
 *      实现业务及流程接口当中的内容
 */
@Service
public class ClassRoomServiceImpl implements ClassRoomService {

    @Autowired
    private ClassRoomDao classRoomDao;


    /**
     * 班级添加方法的实现
     * @param classRoom
     * @return
     */
    @Override
    public int addClassRoom(ClassRoom classRoom) {
        int returnInt = 0;
        /*
         * 1.业务判断
         *          1）班级名称不能重复
         * */
        //1）判断
        String classname = new ClassRoom().getCname();
        if(classname != null){
            //2.数据添加
            int addClass = classRoomDao.addClassRoom(classRoom);
            //3.返回值设置
            returnInt = addClass;
        }else{
            //有相同的角色名
            returnInt = -1;
        }
        return returnInt;
    }


    /**
     * 班级更新方法的实现
     * @param classRoom
     * @return
     */
    @Override
    public int updateClassRoom(ClassRoom classRoom) {
        /*
         * 业务流程判断
         * */
        int isUpdate = 0;
        try {
            isUpdate = classRoomDao.updateClassRoom(classRoom);
        }catch (Exception e){
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因是：" + e.getMessage());
        }
        return isUpdate;
    }


    /**
     * 班级删除方法的实现
     * @param cnum
     * @return
     */
    @Override
    public int delectClassRoom(int cnum) {
        int delClassRoom = 0;
        try {
            //根据班级编号判断
            if(new ClassRoom().getCnum() != 0){
                int delectClassRoom = classRoomDao.delectClassRoom(cnum);
            }else{
                delClassRoom = 1;
            }
        }catch (Exception e){
            delClassRoom = -1;
            System.out.println("删除班级信息时执行SQL报错，信息为：" + e.getMessage());
        }
        return delClassRoom;
    }


    /**
     * 班级表查询
     * @param cnum
     * @return
     */
    @Override
    public List<ClassRoom> selectClassRoom(int cnum) {
        List<ClassRoom> classRooms = classRoomDao.selectClassRoom(cnum);
        return classRooms;
    }
}
